package com.dingding.service.coupon;

import java.util.List;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.dingding.common.core.beans.CouponStore;
import com.dingding.common.core.beans.StoreAssistant;
import com.dingding.common.core.util.ToolUtil;
import com.dingding.facde.activity.dto.UseCouponInfoDTO;
import com.dingding.facde.coupon.IStoreManagerService;
import com.dingding.service.activity.core.dao.IAdvertiseStatDao;
import com.dingding.service.activity.core.dao.ICouponDao;
import com.dingding.service.activity.core.dao.IStoreAssistantDao;
import com.dingding.service.activity.core.dao.IUserCouponDao;
import com.dingding.service.common.core.dao.IPhonevalidateDao;
import com.dingding.service.common.core.dao.IUserAccountDao;
import com.dingding.service.common.core.dao.IUserDetailDao;
import com.dingding.service.common.core.dao.IUserIntegralDao;
import com.dingding.service.common.core.dao.IUserLoginDao;
import com.dingding.service.common.core.dao.IVehicleinfoDao;
import com.dingding.service.store.dao.ICouponStoreDao;

/**
 * @ClassName: IUserManagerService 
 * @Description: 门店管理员表 
 * @author YHQ
 * @date 2016年2月20日 上午10:00:44
 */
@Component("storeManagerService")
public class StoreManagerServiceImpl implements IStoreManagerService {

	private Logger log = Logger.getLogger(this.getClass());

	// 用户优惠券DAO
	@Resource
	protected IUserCouponDao userCouponDao;

	// 优惠券DAO
	@Resource
	protected ICouponDao couponDao;

	// 城市门店DAO
	@Resource
	protected ICouponStoreDao couponStoreDao;

	// 用户详细信息DAO
	@Resource
	protected IUserDetailDao userDetailDao;

	// 用户登录DAO
	@Resource
	protected IUserLoginDao userLoginDao;

	// 用户积分DAO
	@Resource
	protected IUserIntegralDao userIntegralDao;

	// 用户账号DAO
	@Resource
	protected IUserAccountDao userAccountDao;

	@Resource
	protected IVehicleinfoDao vehicleinfoDao;

	// 验证码DAO
	@Resource
	protected IPhonevalidateDao phonevalidateDao;

	// 门店助手DAO
	@Resource
	protected IStoreAssistantDao storeAssistantDao;

	// 推广商DAO
	@Resource
	protected IAdvertiseStatDao advertiseStatDao;

	/**
	 * @Title: managerLogin 
	 * @Description: 门店管理员登录 
	 * @param tellphone	门店管理员登录账户
	 * @param password  门店管理员密码
	 * @author fengshuonan
	 * @return UseCouponInfoDTO 如果登录成功则返回优惠券的详细信息
	 * @Override
	 */
	@Transactional(readOnly = true)
	public UseCouponInfoDTO managerLogin(String tellphone, String password, String couponId) {

		if (ToolUtil.isBlank(tellphone) || ToolUtil.isBlank(password) || ToolUtil.isBlank(couponId)) {
			return null;
		}

		// 根据用户名和密码获取门店管理员登录信息
		StoreAssistant storeAssistant = this.storeAssistantDao.validateUserPwd(tellphone, password);

		if (storeAssistant != null) {

			log.info("查询到店员,获取优惠券信息!" + storeAssistant);

			UseCouponInfoDTO couponInfo = this.couponDao.getUseCouponInfo(couponId);
			couponInfo.setUserId(storeAssistant.getSaId());
			return couponInfo;
		} else {
			return null;
		}
	}

	/**
	 * @Title: managerForgetPassword 
	 * @Description: 门店管理员忘记密码 
	 * @param  tellphone 门店管理员账户
	 * @param  verifyCode 门店管理员账户
	 * @author YHQ
	 * @return boolean    返回类型 
	 */
	@Override
	public boolean managerForgetPassword(String tellphone, String verifyCode) {

		if (ToolUtil.isBlank(tellphone) || ToolUtil.isBlank(verifyCode)) {
			return false;
		}

		// 修改门店管理员密码 true:成功 false:失败
		boolean flag = this.storeAssistantDao.changeStoreUserPwd(tellphone, verifyCode);

		return flag;

	}

	/**
	 * @Title: getStoreInfo
	 * @Description: 根据门店id获取门店详情
	 * @param @param storeId 门店id
	 * @author fengshuonan
	 * @return CouponStore 门店详情
	 * @Override
	 */
	public CouponStore getStoreInfo(String storeId) {

		if (ToolUtil.isBlank(storeId)) {
			log.info("查询门店详情时id为空！StoreManagerServiceImpl:getStoreInfo()");
			return null;
		}

		return this.couponStoreDao.getStoreInfo(storeId);
	}

	/**
	 * @Title: getStroeList
	 * @Description: 获取门店列表
	 * @author fengshuonan
	 * @return List<CouponStore> 门店列表
	 * @Override
	 */
	public List<CouponStore> getStoreList() {

		return this.couponStoreDao.getStroeList();
	}

}
